package html;

import data.UserData;
import haxe.Firebug;
import js.Lib;

import html.states.home.Home;
import html.states.login.Login;

import oboe.controllers.ServerConnection;
import oboe.controllers.StateMachine;
import oboe.controllers.Translator;

import oboe.core.Oboe;

using oboe.util.ISigSlotHelper;

/**
 * ...
 * @author Felipe Manga
 */

class Main extends StateMachine
{
	function new()
	{
		Firebug.redirectTraces();
		
		var translator:Translator = new Translator();
		super( translator );

		this.addChild( new ServerConnection(Lib.window.location.href, "broadcastSignal") );
		
		this.addState( "login", new Login() );
		this.addState( "home", new Home() );
		
		translator.addSignalDown( "onAddToParent", "server_getUserData" );
		translator.addMessage( "permissionDenied", this, "setState", ["login"] );
		translator.addMessage( "userData", this, "setState", function( p:Array<Dynamic> ) { return ["home", p ]; } );
	}
	
	static function main() Oboe.initOboe( {}, Main )
}